package cascade.model {
	import flash.utils.*;
	
	import flight.mvc.ValueObject;
	
	[Bindable]
	[RemoteClass(alias="Revision")]
	public class Revision extends ValueObject {
		
		public var id:uint;
		public var page_id:uint;
		public var user_id:uint;
		
		public var number:uint;
		public var title:String;
		public var description:String;
		public var template:String;
		
		private var _publish:Object;
		private var _expires:Object;
		private var _modified:Object;
		private var _created:Object;
		
		public function Revision() {
			
		}
		
		public function get publish():Object {
			return _publish;
		}
		public function set publish(publish:Object):void {
			_publish = publish is Number ? new Date(Number(publish)*1000) : publish;
		}
		
		public function get expires():Object {
			return _expires;
		}
		public function set expires(expires:Object):void {
			_expires = expires is Number ? new Date(Number(expires)*1000) : expires;
		}
		
		public function get modified():Object {
			return _modified;
		}
		public function set modified(modified:Object):void {
			_modified = modified is Date ? new Date(Number(modified)*1000) : modified;
		}
		
		public function get created():Object {
			return _created;
		}
		public function set created(created:Object):void {
			_created = created is Date ? new Date(Number(created)*1000) : created;
		}
		
		public function prepareToSend():void {
			publish = publish is Date ? (publish as Date).getTime()/1000 : publish;
			expires = expires is Date ? (expires as Date).getTime()/1000 : expires;
			modified = modified is Date ? modified.getTime()/1000 : modified;
			created = created is Date ? created.getTime()/1000 : created;
		}
		
		public function clone():Revision {
			var revision:Revision = new Revision();
			revision.id = id;
			revision.user_id = user_id;
			revision.number = number;
			revision.title = title;
			revision.description = description;
			revision.template = template;
			revision.publish = publish;
			revision.expires = expires;
			revision.modified = modified;
			revision.created = created;
			return revision;
		}
	}
}